<!--
 * @Author: your name
 * @Date: 2021-04-02 14:02:31
 * @LastEditTime: 2021-05-10 14:58:30
 * @LastEditors: Please set LastEditors
 * @Description: 上市产品列表
 * @FilePath: /medicine-web/src/views/products/index.vue
-->
<template>
  <div class="product-container">
    <div class="document-container__result">
      <a-menu v-model="currentTab" mode="horizontal" class="tab-result__outter">
        <a-menu-item v-for="item in tabList" :key="item.label">{{item.label}}</a-menu-item>
      </a-menu>
      <router-view></router-view>
    </div>
  </div>
</template>
<script>
import { mapGetters } from 'vuex'
import emptyData from '@/components/EmptyData/index'
export default {
  name: 'products',
  components: { emptyData },
  data () {
    return {
      currentTab: ['文献集锦'],
      tabList: [
        { label: '文献集锦', value: 1 },
        { label: '临床试验', value: 2 },
        { label: '会议进展', value: 3 },
        { label: '药企资讯', value: 4 },
        { label: '材料总结', value: 5 },
        { label: 'Q&A', value: 6 },
      ],
      pageNum: 1,
    }
  },
  methods: {
    onChange (e) {
      console.log('onChange===========', e)
    },
    // userClick (rawData) {
    //   console.log('userClick=============', rawData)
    //   if (rawData.type === 'download') {
    //     if (rawData && rawData.data && rawData.data.annex && rawData.data.annex.length > 0) {
    //       downLoadPdf(rawData.data.annex[0])
    //     } else {
    //       this.$message.info('暂无文件附件，无法下载。')
    //     }
    //   }
    // },
  },
  // beforeDestroy () {
  //   if (this.$route.path.indexOf('/simple/search') != -1) {
  //     return
  //   }
  //   this.$action('setFilter', {})
  // },
  beforeDestroy () {
    window.removeEventListener('scroll', () => {}, false)
    this.setLocalStorage('currentTab', ['文献集锦'])
  },
  created () {
    this.currentTab = [this.getLocalStorage('currentTab')]
    switch (this.currentTab[0]) {
      case '文献集锦':
        this.$router.replace('/products/index/document', this.$router.length - 1)
      break;
      case '临床试验':
        this.$router.replace('/products/index/clinical', this.$router.length - 1)
      break;
      case '会议进展':
        this.$router.replace('/products/index/meeting', this.$router.length - 1)
      break;
      case '上市产品':
        this.$router.replace('/products/index/products', this.$router.length - 1)
      break;
      case '药企资讯':
        this.$router.replace('/products/index/realinfo', this.$router.length - 1)
      break;
      case '材料总结':
        this.$router.replace('/products/index/summary', this.$router.length - 1)
      break;
      case 'Q&A':
        this.$router.replace('/products/index/qanda', this.$router.length - 1)
      break;
      default:
        this.$router.replace('/products/index/document', this.$router.length - 1)
        break;
    }
  },
  mounted () {
    window.onscroll = (e) => {
      for (let item of this.$router.options.routes[4].children[5].children[0].children) { // 保持menus状态
        item.meta.y = window.pageYOffset
      }
    }
  },
  watch: {
    currentTab: function (val, oldVal) {
      switch (val[0]) {
        case '文献集锦':
          this.$router.replace('/products/index/document', this.$router.length - 1)
        break;
        case '临床试验':
          this.$router.replace('/products/index/clinical', this.$router.length - 1)
        break;
        case '会议进展':
          this.$router.replace('/products/index/meeting', this.$router.length - 1)
        break;
        case '上市产品':
          this.$router.replace('/products/index/products', this.$router.length - 1)
        break;
        case '药企资讯':
          this.$router.replace('/products/index/realinfo', this.$router.length - 1)
        break;
        case '材料总结':
          this.$router.replace('/products/index/summary', this.$router.length - 1)
        break;
        case 'Q&A':
          this.$router.replace('/products/index/qanda', this.$router.length - 1)
        break;
        default:
          this.$router.replace('/products/index/document', this.$router.length - 1)
          break;
      }
      this.setLocalStorage('currentTab', val[0])
    },
    resetCurrentTab: function (val, oldVal) {
      this.currentTab = ['文献集锦']
    }
  }
}
</script>
<style lang="scss" scoped>
@import '~@/assets/styles/flex.scss';
@import '~@/assets/styles/common.scss';
.product-container {
  width: 1200px;
  margin: 0 auto;
  padding: 32px 0px 88px 0px;
  /deep/ .a-btn-container .btn-pattern {
    width: 132px;
    height: 37px;
    font-size: 14px;
    color: #555;
    background-color: #fff;
    border: 1px solid rgba(0, 0, 0, 0.21);
  }
  .document-container__result {
    // margin-top: 28px;
    .main-search__result-container {
      .main-search__result-item {
        @include flex-def;
        .main-search__result-content {
          width: 100%;
          margin-left: 8px;
          li:nth-child(n+2) {
            margin-top: 10px;
            font-size: 14px;
            color: #555;
          }
          li:nth-child(1) {
            font-size: 14px;
            color: #555;
            font-weight: bold;
            cursor: pointer;
          }
          .main-search__result-func {
            @include flex-def;
            @include flex-cCenter;
            @include flex-zBetween;
          }
        }
      }
    }
  }
}
</style>
